package singleton;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 功能:
 * 作者: ldl
 * 时间: 2016-08-12 10:45
 */
public class Singleton {

    private static Singleton singleton;

    private static final Object object = new Object();

    private static Lock lock = new ReentrantLock();

    private Singleton() {
    }


    public static Singleton newInstance() {
        if (singleton == null) {
            try {
                lock.lock();
                if (singleton == null) {
                    singleton = new Singleton();
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }

        }
        return singleton;
    }

}
